<template>
  <div class="todo-header">
    <div class="banxin flex">
      <h2 class="title">TodoList</h2>
      <div class="input">
        <input
          type="text"
          v-model="val"
          @keyup="addToList($event)"
          placeholder="添加ToDO"
        />
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      val: "",
    };
  },
  methods: {
      addToList(e) {
        if (e.which !== 13) return;
      this.$store.commit('addItem',this.val)
      // console.log(this.val);
      this.val = "";
    },
  },
};
</script>
 
<style lang = "less" scoped>
.todo-header {
  background-color: #333;
  height: 100px;
}

.title {
  color: #fff;
}

.input input {
  width: 300px;
  padding-left: 50px;
  height: 60px;
}

.todo-header .flex {
  justify-content: space-between;
  align-items: center;
  height: 100px;
}
</style>